import { createApp } from 'vue';
import App from './App.vue';
import { TUIComponents, TUICore, genTestUserSig } from './TUIKit';
// import TUICallKit
import { TUICallKit } from '@tencentcloud/call-uikit-vue';
import router from "./router"
import './css/global.css';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import axios, { AxiosInstance, AxiosResponse,AxiosError } from "axios";
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import './router/permission'
import echarts from 'echarts'


// 创建 Axios 实例
const http: AxiosInstance = axios.create({
  baseURL: 'http://127.0.0.1:8000/'
});
// 添加请求拦截器，在请求开始时展示进度条
http.interceptors.request.use((config: any) => {
  console.log(config);
  NProgress.start();
  config.headers.Authorization = window.sessionStorage.getItem('token');
  return config;
}, (error: AxiosError) => {
  NProgress.done();
  return Promise.reject(error);
});
// 添加响应拦截器，在响应结束时隐藏进度条
http.interceptors.response.use((response: AxiosResponse): AxiosResponse => {
  console.log(response);
  NProgress.done();
  return response;
}, (error: any) => {
  NProgress.done();
  return Promise.reject(error);
});



const SDKAppID = 1400828049; // Your SDKAppID
const secretKey = '60c58ae3b7eaa37dc2b66075f13a70645a5b01861e1c258f4291a0e4896b8d62'; //Your secretKey
const userID: string | null = localStorage.getItem('account');
const str: string = userID as string;
// init TUIKit
const TUIKit = TUICore.init({
  SDKAppID,
});
// TUIKit add TUIComponents
TUIKit.use(TUIComponents);
// TUIKit add TUICallKit
TUIKit.use(TUICallKit);

// login TUIKit
TUIKit.login({
  userID: str,
  userSig: genTestUserSig({
    SDKAppID,
    secretKey,
    userID,
  }).userSig, // The password with which the user logs in to IM. It is the ciphertext generated by encrypting information such as userID.For the detailed generation method, see Generating UserSig
});
// 将 Axios 实例绑定到Vue原型上
const app = createApp(App)
app.config.globalProperties.$http = http;
app.config.globalProperties.$echarts = echarts
app.use(router as any).use(ElementPlus as any).use(TUIKit);
app.mount('#app');